/*
 *                        .::::.
 *                      .::::::::.
 *                     :::::::::::
 *                  ..:::::::::::'
 *               '::::::::::::'
 *                 .::::::::::
 *            '::::::::::::::..
 *                 ..::::::::::::.
 *               ``::::::::::::::::
 *                ::::``:::::::::'        .:::.
 *               ::::'   ':::::'       .::::::::.
 *             .::::'      ::::     .:::::::'::::.
 *            .:::'       :::::  .:::::::::' ':::::.
 *           .::'        :::::.:::::::::'      ':::::.
 *          .::'         ::::::::::::::'         ``::::.
 *      ...:::           ::::::::::::'              ``::.
 *     ````':.          ':::::::::'                  ::::..
 *                        '.:::::'                    ':'````..
 *
 * @Author: byx
 * @Date: 2022-11-30 18:43:49
 * @LastEditors: byx
 * @LastEditTime: 2022-12-04 01:11:54
 * @version: 1.0
 * @Descripttion: wwww.byx1024.top
 */
import request from 'utils/request'

/**
 * 获取文章列表数据
 * @returns Promise
 */
export const getArticles = params => {
  // 不简写
  return request({
    method: 'GET',
    url: '/mp/articles',
    params,
  })
}

/**
 * 删除文章
 * @param {String} id
 * @returns Promise
 */
export const delArticle = id => {
  // 简写
  return request.delete(`/mp/articles/${id}`)
}

/**
 * 发表文章（草稿）
 * @param {Obj} data
 * @param {String} draft true是，false否
 * @returns Promise
 */
export const addAritcle = (data, draft = false) => {
  return request.post(`/mp/articles?draft=${draft}`, data)
}

/**
 * 获取文章详细信息
 * @param {String} id
 * @returns Promise
 */
export const getArticleById = id => {
  return request.get(`/mp/articles/${id}`)
}

/**
 * 修改文章
 * @param {*} data
 * @param {*} draft
 * @returns Promise
 */
export const updateArticle = (data, draft = false) => {
  return request.put(`/mp/articles/${data.id}?draft=${draft}`, data)
}
